package com.vietthangif.project.Views;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import com.vietthangif.project.contact.Entry;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.vietthangif.project.silentcontact.R;

public class ContactAdapter extends BaseAdapter {
	
	private ArrayList<Entry> contacts;		//contact name and number
	private LayoutInflater inflater;
	
	public ContactAdapter(Activity activity, ArrayList<Entry> contacts) {
		this.contacts = contacts;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return contacts.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return contacts.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View vi = convertView;
		
		if(convertView==null)
            vi = inflater.inflate(R.layout.contact_row, null);
		
		ImageView thumbImage = (ImageView)vi.findViewById(R.id.thumb_image);
		TextView name = (TextView)vi.findViewById(R.id.name);
		TextView numberPhone = (TextView)vi.findViewById(R.id.phone);
		
		Entry contact = contacts.get(position);
		
		name.setText(contact.getName());
		numberPhone.setText(contact.getNumberPhone());
		
		return vi;
	}

}
